package all;

import java.util.HashMap;
import java.util.Map;

/**
 * @author by zhangleishuidihuzhu.com
 * @Date 2023/5/19 17:39
 */
public class TestS {

    public static void main(String[] args) {
        TestS t = new TestS();
        System.out.println(t.findLongestLength("abcabcbb"));
    }


    private int findLongestLength(String str) {
        Map<Character, Integer> map =new HashMap<>();

        char[] array = str.toCharArray();
        int result = 0;
        int index = 0;

        for (int i = 0; i < array.length; i++) {
            char cur = array[i];
            if (map.get(cur)!=null) {
                while (map.get(cur) != null && index<i) {
                    map.remove(str.charAt(index++));
                }
            }
            map.put(cur,i);
            result = Math.max(result, map.size());
        }
        return result;
    }

}
